A general tendency in the development of applications is to include more and more functionality. The increase of functionality typically also increases the complexity of the application development and maintenance. One way to counter the increase in complexity is to implement a “separation of concerns” in the programming development. A separation of concerns is understood to refer to development of programs in modular pieces, each focused on a primary functionality. The primary functionality provided by the module is the “primary concern” for the module. One challenge with separation of concerns is that all programming efforts involve “crosscutting concerns” that do not fit neatly within any one separate module, but rather apply to multiple different functional modules. The classic example of a crosscutting concern is a logging function. The logging function is generally a functionality that applies to most if not all of the modular pieces of the application. Thus, separating the logging functionality into its own separate module does not make sense in traditional separation of concerns programming.
To address the issue of crosscutting concerns, aspect oriented programming (AOP) was developed. AOP generally adds a special class to object-oriented programming environments that allow the creation of a so-called “aspect” that has the functionality of the crosscutting concern. The aspect belongs to a special class that has special properties to allow the aspect code or the crosscutting functionality to be “weaved” into the application during compilation of the application source code. Typically, a specialized loader loads and inserts the aspect code at well-defined points (e.g., the end of a method, the beginning of an exception handler) in the intermediate code of a virtual machine to allow the incorporation of the aspect functionality.
Consider as examples the application of aspects by AspectJ for Java code, and Aspect.pm for Perl, which apply the aspects by directly modifying the application code, or the code that will be evaluated by the virtual machine. Note that all trademarks used herein are used solely for purposes of identification of a product, and all trademarks are the property of their respective owners. AspectJ is available from the ECLIPSE FOUNDATION, which has locations in Ottawa, Ontario Canada and Portland, Oreg. AspectJ applies aspects by providing a custom Java class loader that inserts code to apply the aspects as classes, which are loaded into memory. The Aspect.pm Perl module applies aspects by replacing subroutine entries in the symbol table with wrappers that incorporate the aspect functionality. Such applications are relatively fast for runtime execution. There is a small load-time hit while the code modification, or weaving, takes place, but otherwise the application of aspects in these systems does not require much overhead. However, the application of aspects in traditional system is inflexible.
Aspects as applied externally by specialized loaders are limited to where the aspects can be applied. The application of aspects in traditional implementations change the code evaluated by the virtual machine, but do not directly change how the virtual machine will operate.